home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH02 / CFUNC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-15  |  981 b   |  39 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4.  
  5. /* Generic logic function.  The "Func" parameter contains the 16-bit     */
  6. /* logical function number.  This is actually an encoded truth table    */
  7. /* for the function.  The a, b, c, and d parameters are the inputs to    */
  8. /* the logic function.  If we treat "func" as a 2x2x2x2 array of bits,    */
  9. /* this particular function selects bit "func[d,c,b,a]" from func.    */
  10.  
  11. int
  12. generic(int func, int a, int b, int c, int d)
  13. {
  14.     return (func >> (a + b*2 + c*4 + d*8)) & 1;
  15. }
  16.  
  17. /* Main program to drive the generic logic function written in C.    */
  18.  
  19. main()
  20. {
  21.     int func, a, b, c, d;
  22.  
  23.     do
  24.     {
  25.         printf("Enter function value (hex): ");
  26.         scanf("%x", &func);
  27.         if (func != 0)
  28.         {
  29.             printf("Enter values for d, c, b, & a: ");
  30.             scanf("%d%d%d%d",
  31.                 &d, &c, &b, &a);
  32.  
  33.             printf("The result is %d\n", generic(func,a,b,c,d));
  34.             printf("Func = %x, A=%d, B=%d, C=%d, D=%d\n",
  35.                 func, a, b, c, d);
  36.         }
  37.     } while (func !=0);
  38.  
  39. }